.globl relu

.text
# ==============================================================================
# FUNCTION: Performs an inplace element-wise ReLU on an array of ints
# Arguments:
#   a0 (int*) is the pointer to the array
#   a1 (int)  is the # of elements in the array
# Returns:
#   None
# Exceptions:
#   - If the length of the array is less than 1,
#     this function terminates the program with error code 36
# ==============================================================================
relu:
	# Prologue
    add t1, a1, x0
    add t2, a0, x0
    bgt a1, x0, loop_start
    li a0, 36
    j exit
loop_start:
    beq x0, t1, loop_end
    lw t3, 0(t2)
    bgt t3, x0, loop_continue
    sw x0, 0(t2)
loop_continue:
    addi t2, t2, 4
    addi t1, t1, -1
    j loop_start
loop_end:
	# Epilogue
	ret